package com.cskaoyan.dbutils;

import com.cskaoyan.datasource.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * 创建日期: 2022/07/02 09:58
 *
 * @author ciggar
 */
public class QueryRunnerDemo1 {

    // update

    public static void main(String[] args) throws SQLException {

        // 无参构造
        QueryRunner queryRunner = new QueryRunner();

        Connection connection = DruidUtils.getConnection();
        String sql = "insert into account values (?,?,?)";

        int affectedRows = queryRunner.update(connection, sql, 1988, "金智焕", 8000);
        System.out.println("affectedRows:" + affectedRows);


        // 传入一个数据库连接池
        QueryRunner queryRunner1 = new QueryRunner(DruidUtils.getDataSource());

        int affectedRows2 = queryRunner1.update("delete from account where id in (?,?,?)", 1, 2, 4);

        System.out.println("affectedRows2:" + affectedRows2);


    }
}
